﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Xml;
using V5_Common;

namespace V5_Data {
    /// <summary>
    /// 网站配置
    /// </summary>
    public class V5ConfigHelper {

        private static readonly V5ConfigHelper m_Instance = new V5ConfigHelper();
        /// <summary>
        /// 
        /// </summary>
        public static V5ConfigHelper Instance {
            get { return m_Instance; }
        }

        private DataTable _dtConfig = new DataTable();
        private DataRow _View = null;

        /// <summary>
        /// 配置字段
        /// </summary>
        public DataRow View {
            get {
                if (_View == null) {
                    Init();
                }
                return _View;
            }
        }

        public V5ConfigHelper() {

        }
        private string _TemplatePath;
        /// <summary>
        /// 模板地址
        /// </summary>
        public string TemplatePath {
            get {
                _TemplatePath = "template/" + View["TemplatePath"];
                return _TemplatePath;
            }
        }

        private string _TemplateDir = "Default";
        /// <summary>
        /// 模板目录
        /// </summary>
        public string TemplateDir {
            get {
                _TemplateDir = View["TemplatePath"].ToString();
                return _TemplateDir;
            }
        }

        private string _SiteUrl = "/";
        /// <summary>
        /// 站点地址
        /// </summary>
        public string SiteUrl {
            get { return _SiteUrl; }
            set { _SiteUrl = value; }
        }

        public void Init() {
            _dtConfig = V5.SQL.Query_By("*", "Tbl_Config", "", "ID Desc", 1);
            _View = _dtConfig.Rows[0];
        }

        public void Clear() {
            if (View != null) {
                _dtConfig.Rows.Remove(View);
            }
        }
    }
}